<?php
//
// Configuration for a postgresql connection
//
$host = "localhost";
$user = "postgres";
$password = "123456";
$dbname = "lanchonete";


//
// Set TimeZone
//
$timezone = "America/Bahia";
date_default_timezone_set( $timezone );


// 
// Get a db connection
//
function dbConnect() {
  $connectionString = "host=" . $GLOBALS['host'] . " user=" . $GLOBALS['user'] . 
                      " password=" . $GLOBALS['password'] . 
                      " dbname=" . $GLOBALS['dbname'];
                      
  return pg_connect($connectionString);
}


//
// Executes an sql SELECT query. Returns an array with the selected rows.
//
function executeSelect( $sql ) {
  $queryResult = pg_query( $sql ); 
 
  $result = array();
  while ( $row = pg_fetch_assoc($queryResult) ) {
    array_push( $result, $row );
  }
   
  return $result;
}


//
// Executes others querys, as delete or update. Returns the number of affected rows.
//
function executeQuery( $sql ) {
  $queryResult = pg_query( $sql ); 
  $queryAffectedRows = pg_affected_rows( $queryResult );

  return $queryAffectedRows;
}

?>
